I have a class: BaseResourceModel on my Angular application
export abstract class BaseResourceModel{
id?: any;
description?: string;
name?: string;
}
And several other classes inheriting from it like this:
import { BaseResourceModel } from '@core/models/_base/base-resource.model';
export class CityModel extends BaseResourceModel{
constructor(ufId?: number){
super();
}
static factory(obj: any): CityModel{
return Object.assign(new CityModel(), obj);
}
}
I would like to know if there's a way or a proper way to put the static factory method on the BaseResourceModel, but specifying for each heir the type of assignment, like this:
export abstract class BaseResourceModel{
id?: any;
description?: string;
name?: string;
static factory(obj, class){
//ex.: class parameter will get here like CityModel
return Object.assign(new class(), obj);
}
}